/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package lyra;

import java.awt.FileDialog;
import java.awt.Frame;
import java.io.File;
import java.util.List;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.Objects;
import javax.swing.table.AbstractTableModel;
import javax.persistence.EntityTransaction;
import javax.persistence.Query;
import javax.swing.ListSelectionModel;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

import lyra.pojos.*;
import org.w3c.dom.DOMException;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;


/**
 *
 * @author Koustas, Marmaridis, Mariolou
 */
public class FPlayList extends javax.swing.JInternalFrame {

    private Playlist playlist;
    private Playlist OriginalPlaylist;
    private List<Object[]> curPlayListSongs;
    private List<Object[]> curAvailableSongs;
    private boolean bChanges = false;
    private boolean bFormClosing = false;
    private boolean addSongsVisible = false;

    private FListPlayList parentForm;

    private SimpleDateFormat sDF = new SimpleDateFormat("dd/MM/yyyy");
    
    private class PlayListSongTableModel extends AbstractTableModel 
    {
   
        private List<Object[]> vwplaylistsongs;
           
        private final String[] columnNames = new String[] {"PlayListID", "SongID", "Τίτλος", "Διάρκεια", "Καλλιτέχνης/Συγκρότημα"};
        private final Class[] columnClass = new Class[] {Long.class, long.class, String.class, Integer.class, String.class};
 
        public PlayListSongTableModel(List<Object[]> vwplaylistsongs)
        {
           this.vwplaylistsongs = vwplaylistsongs;
        }

        public void removeRow(int row) {
            vwplaylistsongs.remove(row);
        }

        public void clearRows() {
            vwplaylistsongs.clear();
        }

        public void addRow(Object[] newRow) {
            vwplaylistsongs.add(newRow);
        }
        
        @Override
        public String getColumnName(int column)
        {
            return columnNames[column];
        }
 
        @Override
        public Class<?> getColumnClass(int columnIndex)
        {
            return columnClass[columnIndex];
        }

        @Override
        public int getColumnCount()
        {
            return columnNames.length;
        }

        @Override
        public int getRowCount()
        {
            return vwplaylistsongs.size();
        }
        
        @Override
        public boolean isCellEditable(int row, int col) {
            return false;
        }
        
        @Override
        public Object getValueAt(int rowIndex, int columnIndex)
        {
            try {
                Object[] row = (Object[]) this.vwplaylistsongs.get(rowIndex);
                return row[columnIndex];
            } catch (Exception ex) {
                    ex.printStackTrace(System.out);
                    return null;
            }

        }
    }
    
    private class SongTableModel extends AbstractTableModel 
    {
   
       private List<Object[]> vwsongs;
           
       private final String[] columnNames = new String[] {"SongID", "Τίτλος", "Διάρκεια", "Καλλιτέχνης/Συγκρότημα"};
        private final Class[] columnClass = new Class[] {Long.class, String.class, Integer.class, String.class};
 
        public SongTableModel(List<Object[]> vwsongs)
        {
           this.vwsongs = vwsongs;
        }
     
        @Override
        public String getColumnName(int column)
        {
            return columnNames[column];
        }
 
        @Override
        public Class<?> getColumnClass(int columnIndex)
        {
            return columnClass[columnIndex];
        }

        @Override
        public int getColumnCount()
        {
            return columnNames.length;
        }

        @Override
        public int getRowCount()
        {
            return vwsongs.size();
        }
        
        @Override
        public boolean isCellEditable(int row, int col) {
            return false;
        }
        
        @Override
        public Object getValueAt(int rowIndex, int columnIndex)
        {
            try {
                Object[] row = (Object[]) this.vwsongs.get(rowIndex);
                return row[columnIndex];
            } catch (Exception ex) {
                    ex.printStackTrace(System.out);
                    return null;
            }

        }
   }

    private void fillPlayListSongs(long playlistID) {
       
        curPlayListSongs = new ArrayList();
        
        if (playlistID == -1) {
            Query qPlayListSongs = LYRA.e.createNativeQuery("SELECT pls.* FROM ADMIN1.vwPlayListSongs pls WHERE 1=2");
            curPlayListSongs = (List<Object[]>)qPlayListSongs.getResultList();
        } else {
            Query qPlayListSongs = LYRA.e.createNativeQuery("SELECT pls.* FROM ADMIN1.vwPlayListSongs pls WHERE pls.PlayListID = " + playlistID);
            curPlayListSongs =  (List<Object[]>)qPlayListSongs.getResultList();
        }
        
        PlayListSongTableModel model = new PlayListSongTableModel(curPlayListSongs);
        
        tblSongsPlayList.setModel(model);
        this.tblSongsPlayList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        
        for (int intCol=0;intCol<=1;intCol++) {
            if (tblSongsPlayList.getColumnModel().getColumnCount() > intCol) {
                tblSongsPlayList.getColumnModel().getColumn(intCol).setMinWidth(0);
                tblSongsPlayList.getColumnModel().getColumn(intCol).setMaxWidth(0);
            }
        }
        this.tblSongsPlayList.setCellSelectionEnabled(false); 
        this.tblSongsPlayList.setRowSelectionAllowed(true); 

    }
   
   private void fillAvailableSongs(String strSearchText) {
       
        curAvailableSongs = new ArrayList();
        
        Query qAvailableSongs = LYRA.e.createNativeQuery("SELECT sng.* FROM ADMIN1.vwSongs sng WHERE UPPER(sng.Title) LIKE '%" + strSearchText.toUpperCase() + "%' OR UPPER(sng.ArtistOrMusicGroupName) LIKE '%" + strSearchText.toUpperCase() + "%'");
        curAvailableSongs = (List<Object[]>)qAvailableSongs.getResultList();
        
        SongTableModel model = new SongTableModel(curAvailableSongs);
        
        tblAvailableSongs.setModel(model);
        this.tblAvailableSongs.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
          
        if (tblAvailableSongs.getColumnModel().getColumnCount() > 0) {
            tblAvailableSongs.getColumnModel().getColumn(0).setMinWidth(0);
            tblAvailableSongs.getColumnModel().getColumn(0).setMaxWidth(0);
        }

        this.tblAvailableSongs.setCellSelectionEnabled(false); 
        this.tblAvailableSongs.setRowSelectionAllowed(true); 

    }
   
    public FPlayList(FListPlayList parent) {

        OriginalPlaylist = new Playlist();
        
        initComponents();
        
        this.parentForm = parent;
        
        this.setTitle("Εισαγωγή στοιχείων λίστας");
        Insertion();
        dtDateCreated.setFormats("dd/MM/yyyy");
        setLockCtrls(bChanges);
        fillPlayListSongs(-1);
        setSearchAvailableSongs(false);
        
        LYRA.setFrameIcon(this,"playlist20.png");
        parentForm.EnableDisableForm(false);
    }
    
    public FPlayList(FListPlayList parent, Playlist art ) {
        
        OriginalPlaylist = art;
        initComponents();
        playlist = art;
        this.parentForm = parent;
        this.setTitle("Μεταβολή στοιχείων λίστας");
        dtDateCreated.setFormats("dd/MM/yyyy");
        setLockCtrls(bChanges);
        fillPlayListSongs(art.getPlaylistid());
        setSearchAvailableSongs(false);

        LYRA.setFrameIcon(this,"playlist20.png");
        parentForm.EnableDisableForm(false);
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        LYRAPUEntityManager = java.beans.Beans.isDesignTime() ? null : javax.persistence.Persistence.createEntityManagerFactory("LYRAPU").createEntityManager();
        lyra.pojos.Playlist playlist = OriginalPlaylist;
        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        tbarManage = new javax.swing.JToolBar();
        tbbModify = new javax.swing.JButton();
        tbbInsert = new javax.swing.JButton();
        tbbDelete = new javax.swing.JButton();
        tbbExit = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        lblName = new javax.swing.JLabel();
        txtName = new javax.swing.JTextField();
        lblDateCreated = new javax.swing.JLabel();
        dtDateCreated = new org.jdesktop.swingx.JXDatePicker();
        jScrollPane3 = new javax.swing.JScrollPane();
        tblAvailableSongs = new javax.swing.JTable();
        btnAddSongs = new javax.swing.JButton();
        btnDeleteSongs = new javax.swing.JButton();
        txtSearchAvailableSongs = new javax.swing.JTextField();
        lblSearchAvailableSongs = new javax.swing.JLabel();
        btnSearchAvailableSongs = new javax.swing.JButton();
        lblSongsPlayList = new javax.swing.JLabel();
        jScrollPane4 = new javax.swing.JScrollPane();
        tblSongsPlayList = new javax.swing.JTable();
        lblAvailableSongs = new javax.swing.JLabel();
        btnAddSelectedSongsToPlayList = new javax.swing.JButton();
        btnExportToXML = new javax.swing.JButton();
        btnImportFromXML = new javax.swing.JButton();

        setClosable(true);
        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("Φόρμα Διαχείρισης Λίστας");
        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameClosing(evt);
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
            }
        });

        tbarManage.setFloatable(false);
        tbarManage.setRollover(true);

        tbbModify.setText("Αποθήκευση");
        tbbModify.setFocusable(false);
        tbbModify.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        tbbModify.setPreferredSize(new java.awt.Dimension(50, 50));
        tbbModify.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        tbbModify.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tbbModifyActionPerformed(evt);
            }
        });
        tbarManage.add(tbbModify);

        tbbInsert.setText("Εισαγωγή");
        tbbInsert.setFocusable(false);
        tbbInsert.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        tbbInsert.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        tbbInsert.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tbbInsertActionPerformed(evt);
            }
        });
        tbarManage.add(tbbInsert);

        tbbDelete.setText("Διαγραφή");
        tbbDelete.setFocusable(false);
        tbbDelete.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        tbbDelete.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        tbbDelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tbbDeleteActionPerformed(evt);
            }
        });
        tbarManage.add(tbbDelete);

        tbbExit.setText("Έξοδος");
        tbbExit.setFocusable(false);
        tbbExit.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        tbbExit.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        tbbExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tbbExitActionPerformed(evt);
            }
        });
        tbarManage.add(tbbExit);

        jPanel1.setBackground(new java.awt.Color(204, 255, 255));

        lblName.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        lblName.setText("Περιγραφή:");

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, playlist, org.jdesktop.beansbinding.ELProperty.create("${name}"), txtName, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        txtName.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtNameActionPerformed(evt);
            }
        });
        txtName.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtNameKeyTyped(evt);
            }
        });

        lblDateCreated.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        lblDateCreated.setText("Ημερομηνία δημιουργίας:");

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, playlist, org.jdesktop.beansbinding.ELProperty.create("${datecreated}"), dtDateCreated, org.jdesktop.beansbinding.BeanProperty.create("date"));
        bindingGroup.addBinding(binding);

        dtDateCreated.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                dtDateCreatedKeyTyped(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(lblDateCreated, javax.swing.GroupLayout.DEFAULT_SIZE, 128, Short.MAX_VALUE)
                    .addComponent(lblName, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, 232, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(dtDateCreated, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblName, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblDateCreated)
                    .addComponent(dtDateCreated, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(36, Short.MAX_VALUE))
        );

        tblAvailableSongs.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        tblAvailableSongs.getTableHeader().setReorderingAllowed(false);
        tblAvailableSongs.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblAvailableSongsMouseClicked(evt);
            }
        });
        jScrollPane3.setViewportView(tblAvailableSongs);

        btnAddSongs.setText("Εισαγωγή Τραγουδιού");
        btnAddSongs.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddSongsActionPerformed(evt);
            }
        });

        btnDeleteSongs.setText("Διαγραφή Τραγουδιού");
        btnDeleteSongs.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDeleteSongsActionPerformed(evt);
            }
        });

        txtSearchAvailableSongs.setToolTipText("Πληκτρολογήστε μέρος από το ονοματεπώνυμο καλλιτέχνη, τίτλο συγκροτήματος ή τραγουδιού");

        lblSearchAvailableSongs.setText("Πεδίο Αναζήτησης:");

        btnSearchAvailableSongs.setText("Αναζήτηση");
        btnSearchAvailableSongs.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSearchAvailableSongsActionPerformed(evt);
            }
        });

        lblSongsPlayList.setBackground(new java.awt.Color(51, 255, 51));
        lblSongsPlayList.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblSongsPlayList.setText("Λίστα Τραγουδιών");

        tblSongsPlayList.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        tblSongsPlayList.getTableHeader().setReorderingAllowed(false);
        jScrollPane4.setViewportView(tblSongsPlayList);

        lblAvailableSongs.setBackground(new java.awt.Color(51, 255, 51));
        lblAvailableSongs.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblAvailableSongs.setText("Πίνακας Διαθέσιμων Τραγουδιών");

        btnAddSelectedSongsToPlayList.setText("Προσθήκη Επιλεγμένου Τραγουδιού στη Λίστα Τραγουδιών");
        btnAddSelectedSongsToPlayList.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddSelectedSongsToPlayListActionPerformed(evt);
            }
        });

        btnExportToXML.setText("Εξαγωγή Λίστας σε XML");
        btnExportToXML.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnExportToXMLActionPerformed(evt);
            }
        });

        btnImportFromXML.setText("Εισαγωγή Λίστας από αρχείο XML");
        btnImportFromXML.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnImportFromXMLActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btnAddSongs)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(39, 39, 39)
                                .addComponent(lblSearchAvailableSongs)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(btnDeleteSongs)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnExportToXML)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnImportFromXML)
                                .addGap(0, 0, Short.MAX_VALUE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(txtSearchAvailableSongs, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnSearchAvailableSongs, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(tbarManage, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lblSongsPlayList, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lblAvailableSongs, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(166, 166, 166)
                .addComponent(btnAddSelectedSongsToPlayList)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 628, Short.MAX_VALUE)
                    .addContainerGap()))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(tbarManage, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblSongsPlayList)
                .addGap(131, 131, 131)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnAddSongs)
                    .addComponent(btnDeleteSongs)
                    .addComponent(btnExportToXML)
                    .addComponent(btnImportFromXML))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtSearchAvailableSongs, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblSearchAvailableSongs)
                    .addComponent(btnSearchAvailableSongs))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblAvailableSongs)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnAddSelectedSongsToPlayList)
                .addContainerGap())
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(158, 158, 158)
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(233, Short.MAX_VALUE)))
        );

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void StartEdit()
    {
        setLockCtrls(false);
        //setChanges(false);
    }
            
    private void FinisEdit()
    {
        setLockCtrls(true);
        tbbModify.setEnabled(true);
        //tbbModify.setIcon("imgUpdate.png");
    }
    
    private void setLockCtrls(boolean lock)
    {
        if (lock) 
        {
            tbbModify.setText("Μεταβολή");
            tbbExit.setText("Έξοδος");
        }
        else
        {
            tbbModify.setText("Αποθήκευση");
            tbbExit.setText("Ακύρωση");
        }

        tbbModify.setEnabled(bChanges);
        tbbInsert.setEnabled(lock);
        tbbDelete.setEnabled(lock);
        btnAddSelectedSongsToPlayList.setEnabled(!lock);
        btnAddSongs.setEnabled(!lock);
        btnDeleteSongs.setEnabled(!lock);
        //btnExportToXML.setEnabled(!lock);
        btnImportFromXML.setEnabled(!lock);
    
        txtName.setEditable(!lock);
        txtName.setEnabled(!lock);
        dtDateCreated.setEnabled(!lock);
        dtDateCreated.setEditable(!lock);
    }
    
    private boolean isDataValid()
    {
        //Έλεγχος ύπαρξης περιγραφής
        if ( (txtName.getText().trim()).length() == 0 )
        {
            LYRA.MsgBox("Πρέπει να δοθεί περιγραφή υποχρεωτικά", "ΠΡΟΣΟΧΗ");
            txtName.setFocusable(true);
            return false;
        }

        if ((curPlayListSongs == null) || curPlayListSongs.isEmpty()) {
            LYRA.MsgBox("Δεν υπάρχουν τραγούδια στη λίστα", "ΠΡΟΣΟΧΗ");
            return false;
        }

        int TotalDuration = 0;
        for (int curRow=0;curRow<curPlayListSongs.size();curRow++) {
            TotalDuration += (int)curPlayListSongs.get(curRow)[3];
        }
        if (TotalDuration < (30*60)) {
             LYRA.MsgBox("Η διάρκεια της λίστας είναι μικρότερη από μισή ώρα", "ΠΡΟΣΟΧΗ");
             return false;
        }
        //αν φτάσει ως εδώ τα δεδομένα είναι ΟΚ
        return true;
    }
            
    private void tbbModifyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tbbModifyActionPerformed
        UpdatePlayList();
    }//GEN-LAST:event_tbbModifyActionPerformed

    private void tbbInsertActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tbbInsertActionPerformed
        Insertion();
    }//GEN-LAST:event_tbbInsertActionPerformed

    private void tbbDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tbbDeleteActionPerformed
        DeletePlayList();
    }//GEN-LAST:event_tbbDeleteActionPerformed

    private void  DeletePlayList() {
        //Διαγραφή λίστας
        if ( LYRA.yesno("Θέλετε σίγουρα να διαγραφεί η λίστα " +  playlist.getName().trim() ) == 0 )
        {
            try {
                EntityTransaction et = null;
                et = LYRA.e.getTransaction();
                et.begin();
                
                Query queryDelete =  LYRA.e.createNativeQuery("DELETE FROM ADMIN1.Playlist a WHERE a.PLAYLISTID = " + playlist.getPlaylistid().toString());
                queryDelete.executeUpdate();

                et.commit();
                parentForm.RefreshPlayListTable();
                //Ενεργοποίηση της προηγούμενης φόρμας
                //Κλείσιμο φόρμας
                parentForm.EnableDisableForm(true);
                dispose();
            }
            catch (Exception e) {
                LYRA.MsgBox(e.getMessage(),"ΠΡΟΣΟΧΗ");
            }
            
        }
    }

    private boolean CloseForm() {
        
        if (!tbbExit.isEnabled()) return false;
        
        if (tbbExit.getText()=="Έξοδος")
        {
            LYRA.e.clear();
            parentForm.RefreshPlayListTable();
            parentForm.setEnabled(true);
            return true;
        }
        else
        {
            if (bChanges)
            {
                if ( LYRA.yesno("Είστε σίγουροι ότι θέλετε να χαθούν οι αλλαγές; ") == 0 )
                {
                    LYRA.e.clear();
                    parentForm.RefreshPlayListTable();
                    return true;
                } else {
                    FinisEdit();
                }
             } else {
                return true;
            }
        }
        return false;
    }
    
    private void tbbExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tbbExitActionPerformed
        if (CloseForm()) {
            bFormClosing = true;
            parentForm.EnableDisableForm(true);
            dispose();
        }       
    }//GEN-LAST:event_tbbExitActionPerformed

    private void dtDateCreatedKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_dtDateCreatedKeyTyped
        setChanges(true);
    }//GEN-LAST:event_dtDateCreatedKeyTyped

    private void txtNameKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNameKeyTyped
        setChanges(true);
    }//GEN-LAST:event_txtNameKeyTyped

    private void txtNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtNameActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtNameActionPerformed

    private void setSearchAvailableSongs(boolean showhide) {
        tblAvailableSongs.setVisible(showhide);
        btnAddSelectedSongsToPlayList.setVisible(showhide);
        btnSearchAvailableSongs.setVisible(showhide);
        lblSearchAvailableSongs.setVisible(showhide);
        txtSearchAvailableSongs.setVisible(showhide);
        jScrollPane3.setVisible(showhide);
        lblAvailableSongs.setVisible(showhide);
        if (showhide) {
            btnAddSongs.setText("Ακύρωση Εισαγωγής");
            this.setSize(this.getWidth(), 560);
        } else {
            btnAddSongs.setText("Εισαγωγή Τραγουδιού");
            this.setSize(this.getWidth(), 360);
        }
    }
    
    private void btnAddSongsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddSongsActionPerformed
        addSongsVisible=!addSongsVisible;
        setSearchAvailableSongs(addSongsVisible);
    }//GEN-LAST:event_btnAddSongsActionPerformed

    private void btnAddSelectedSongsToPlayListActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddSelectedSongsToPlayListActionPerformed
        
        if (tblAvailableSongs.getSelectedRowCount() > 0 ) {
            int TableRowToAdd = tblAvailableSongs.getSelectedRow();
                //"PlayListID", "SongsID", "Τίτλος", "Διάρκεια", "Καλλιτέχνης/Συγκρότημα"
            
            for (int curRow=0; curRow<tblSongsPlayList.getRowCount(); curRow++) {
                if (Objects.equals((Long)tblSongsPlayList.getValueAt(curRow, 1), (Long)tblAvailableSongs.getValueAt(TableRowToAdd, 0))) {
                    LYRA.MsgBox("Το συγκεκριμένο τραγούδι υπάρχει ήδη στη λίστα !", "ΠΡΟΣΟΧΗ");
                    return;
                }
            }
                        
           ((PlayListSongTableModel)tblSongsPlayList.getModel()).addRow(new Object[] {playlist.getPlaylistid(), 
                                                                                      tblAvailableSongs.getValueAt(TableRowToAdd, 0),
                                                                                      tblAvailableSongs.getValueAt(TableRowToAdd, 1),
                                                                                      tblAvailableSongs.getValueAt(TableRowToAdd, 2),
                                                                                      tblAvailableSongs.getValueAt(TableRowToAdd, 3)});
           ((PlayListSongTableModel)tblSongsPlayList.getModel()).fireTableRowsInserted(tblSongsPlayList.getRowCount(), tblSongsPlayList.getRowCount());
           setChanges(true);
           
        }
        
    }//GEN-LAST:event_btnAddSelectedSongsToPlayListActionPerformed

    private void btnSearchAvailableSongsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSearchAvailableSongsActionPerformed
        fillAvailableSongs(txtSearchAvailableSongs.getText());
    }//GEN-LAST:event_btnSearchAvailableSongsActionPerformed

    private void btnDeleteSongsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeleteSongsActionPerformed
        if (tblSongsPlayList.getSelectedRowCount() > 0) {
            int TableRowToDelete = tblSongsPlayList.getSelectedRow();
            ((PlayListSongTableModel)tblSongsPlayList.getModel()).removeRow(TableRowToDelete);
            ((PlayListSongTableModel)tblSongsPlayList.getModel()).fireTableRowsDeleted(TableRowToDelete, TableRowToDelete);
            setChanges(true);
        } else {
            LYRA.MsgBox("Επιλέξτε πρώτα τραγούδι προς διαγραφή", "ΠΡΟΣΟΧΗ");        
        }
    }//GEN-LAST:event_btnDeleteSongsActionPerformed

    private void btnExportToXMLActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExportToXMLActionPerformed
         
        // this will export an xml file with the contents of the current playlist
        try {
            
            FileDialog fdSave = new FileDialog((Frame)null,"Save playlist to XML",FileDialog.SAVE);
            fdSave.setVisible(true);
            if (fdSave.getFile() == null ) {
                return;
            }
            String xmlDirectory = fdSave.getDirectory();
            String xmlFileName = fdSave.getFile();
            fdSave.dispose();
                        
            DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); // Δημιουργία parser που παράγει το DOM XML αρχείων
            DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); // Δυνατότητα δημιουργίας των στιγμιότυπων του XML αρχείου από το DOM
            Document doc = docBuilder.newDocument(); // αναφέρεται στο XML αρχείο, είναι η ιδεατή ρίζα του δέντρου
            // δημιουργώ την ρίζα playlist
            Element rootElement = doc.createElement("playlists"); // δημιουργία tag playlist
            doc.appendChild(rootElement); // προσθήκη tag ως παιδί του κόμβου  rootElement
            {
                Element xml_playlist = doc.createElement("playlist"); // δημιουργώ ένα   στοιχείο με το όνομα person
                rootElement.appendChild(xml_playlist); // τον συνδέω με τον τρέχοντα κόμβο
                {
                    Attr attr = doc.createAttribute("name"); 
                    if (playlist.getName() == null) {
                        attr.setValue(null);
                    } else {
                        attr.setValue(playlist.getName()); 
                    }
                    xml_playlist.setAttributeNode(attr);
                }
                {
                    Attr attr = doc.createAttribute("datecreated"); 
                    if (playlist.getDatecreated() == null) {
                        attr.setValue(null);
                    } else {
                        attr.setValue(playlist.getDatecreated().toString()); 
                    }
                    xml_playlist.setAttributeNode(attr);
                }
                Element playlistsongs = doc.createElement("playlistsongs");
                int totalSongs = tblSongsPlayList.getRowCount();
                if (totalSongs != 0) {
                    for (int curSong=0; curSong<totalSongs; curSong++) {
                        Element playlistsong = doc.createElement("playlistsong");
                        Attr attr = doc.createAttribute("song"); 
                        attr.setValue(((Long)(tblSongsPlayList.getValueAt(curSong,1))).toString()); 
                        playlistsong.setAttributeNode(attr);
                        playlistsongs.appendChild(playlistsong);
                    }
                }
                xml_playlist.appendChild(playlistsongs);
                
            }
            // γράφω όλα τα παραπάνω σε ένα αρχείο xml
            TransformerFactory transformerFactory = TransformerFactory.newInstance();
            Transformer transformer = transformerFactory.newTransformer();
            DOMSource source = new DOMSource(doc);
            StreamResult result;
            //δημιουργώ το αρχείο xml
            result = new StreamResult(new File(xmlDirectory, xmlFileName));
            transformer.transform(source, result);
            LYRA.MsgBox("File saved!","");
        } catch (ParserConfigurationException | DOMException | TransformerException ex) {
            ex.printStackTrace(System.out);
            LYRA.MsgBox(ex.toString(), "ΠΡΟΒΛΗΜΑ");
        } catch (Exception ex) {
            ex.printStackTrace(System.out);
            LYRA.MsgBox(ex.toString(), "ΠΡΟΒΛΗΜΑ");
        }
    
    }//GEN-LAST:event_btnExportToXMLActionPerformed

    private void btnImportFromXMLActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnImportFromXMLActionPerformed
        // this will replace playlist info and songs from a saved xml file
         try {
            
            FileDialog fdLoad = new FileDialog((Frame)null,"Load playlist from XML", FileDialog.LOAD);
            fdLoad.setMultipleMode(false);
            fdLoad.setVisible(true);
            if (fdLoad.getFile() == null ) {
                return;
            }
            String xmlDirectory = fdLoad.getDirectory();
            String xmlFileName = fdLoad.getFile();
            fdLoad.dispose();
            
            DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); // Δημιουργία parser που παράγει το DOM XML αρχείων
            DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); // Δυνατότητα δημιουργίας των στιγμιότυπων του XML αρχείου από το DOM
            Document doc = docBuilder.parse(xmlDirectory + xmlFileName); // αναφέρεται στο XML αρχείο, είναι η ιδεατή ρίζα του δέντρου

            if (doc.getDocumentElement().getNodeName().equals("playlists") == false) {
                throw new Exception("Invalid XML format!");
            }
            
            {
                NodeList xml_playlists = doc.getElementsByTagName("playlist");
                if (xml_playlists.getLength() != 1) {
                    throw new Exception("Invalid XML format!");
                }

                setChanges(true);
                //clear tblSongsPlayList.
                
                if (xml_playlists.item(0).getNodeType() == Node.ELEMENT_NODE) {
                    Element xml_playlist = (Element) xml_playlists.item(0);
                    txtName.setText(xml_playlist.getAttribute("name"));
                    if (xml_playlist.getAttribute("datecreated") != "") {
                        dtDateCreated.setDate(sDF.parse(xml_playlist.getAttribute("datecreated")));
                    } else {
                        dtDateCreated.setDate(null);
                    }
                    
                    ((PlayListSongTableModel)tblSongsPlayList.getModel()).clearRows();
                                        
                    NodeList a_xml_playlistsongs = xml_playlist.getElementsByTagName("playlistsongs");
                    Element xml_playlistsongs = (Element) a_xml_playlistsongs.item(0);
                    if (xml_playlistsongs.hasChildNodes()) {

                        List<Object[]> allAvailableSongs = new ArrayList();
                        Query qAllAvailableSongs = LYRA.e.createNativeQuery("SELECT sng.* FROM ADMIN1.vwSongs sng");
                        allAvailableSongs = (List<Object[]>)qAllAvailableSongs.getResultList();
        
                        NodeList songs = xml_playlistsongs.getChildNodes();
                        for (int i=0;i<songs.getLength();i++) {
                            if (songs.item(i).getNodeType() == Node.ELEMENT_NODE) {
                                Element song = (Element) songs.item(i);
                                Long songid = Long.parseLong(song.getAttribute("song"));
                                
                                boolean skipsong = false;
                                for (int curRow=0; curRow<tblSongsPlayList.getRowCount(); curRow++) {
                                    if (Objects.equals((Long)tblSongsPlayList.getValueAt(curRow, 1), songid)) {
                                        skipsong = true;
                                        //LYRA.MsgBox("Το συγκεκριμένο τραγούδι υπάρχει ήδη στη λίστα !", "ΠΡΟΣΟΧΗ");
                                        //return;
                                    }
                                }
                                
                                System.out.println(songid);
                        
                                if (skipsong == false) {
                                    for (Object[] allAvailableSong : allAvailableSongs) {
                                        if (allAvailableSong[0].equals(songid)) {
                                            ((PlayListSongTableModel)tblSongsPlayList.getModel()).addRow(new Object[]{playlist.getPlaylistid(), songid, allAvailableSong[1], allAvailableSong[2], allAvailableSong[3]});
                                        }
                                    }
                                }
                            }
                        }
                        
                        ((PlayListSongTableModel)tblSongsPlayList.getModel()).fireTableDataChanged();

                    }
                    
                }
            }
            LYRA.MsgBox("File loaded!","");
        } catch (ParserConfigurationException | DOMException | TransformerException ex) {
            ex.printStackTrace(System.out);
            LYRA.MsgBox(ex.toString(), "ΠΡΟΒΛΗΜΑ");
        } catch (Exception ex) {
            ex.printStackTrace(System.out);
            LYRA.MsgBox(ex.toString(), "ΠΡΟΒΛΗΜΑ");
        }
    
    }//GEN-LAST:event_btnImportFromXMLActionPerformed

    private void formInternalFrameClosing(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameClosing
        if (!bFormClosing) {
            if (CloseForm()) {
                bFormClosing = true;
                parentForm.EnableDisableForm(true);
                dispose();
            }
        } else {
            parentForm.EnableDisableForm(true);
            dispose();
        }
    }//GEN-LAST:event_formInternalFrameClosing

    private void tblAvailableSongsMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblAvailableSongsMouseClicked
        if (evt.isControlDown()) {
            btnAddSelectedSongsToPlayListActionPerformed(null);
        }
    }//GEN-LAST:event_tblAvailableSongsMouseClicked

    private void UpdatePlayList() {

        if (tbbModify.getText()=="Μεταβολή")
        {
            StartEdit();
        }
        else
        {
            if (isDataValid())
            {
                
                EntityTransaction et = null;
                
                
                try {
                    
                    Query mQuerySong = LYRA.e.createQuery("SELECT sng FROM Song sng");
                    Collection<Song> sng = (Collection<Song>) mQuerySong.getResultList();

                    et = LYRA.e.getTransaction();
                    et.begin();
    
                    if (playlist.getPlaylistid() != null) {
                        Query queryDelete =  LYRA.e.createNativeQuery("DELETE FROM ADMIN1.PlayListSong pls WHERE pls.PlayListID = " + playlist.getPlaylistid().toString());
                        queryDelete.executeUpdate();
                    }

                    if (playlist.getPlaylistsongCollection() == null) {
                        Collection<Playlistsong> emptyCollection = new ArrayList<Playlistsong>();
                        playlist.setPlaylistsongCollection(emptyCollection);
                    } else {
                        playlist.getPlaylistsongCollection().clear();
                    }
                    Collection <Playlistsong> mPlayListSongCollection = playlist.getPlaylistsongCollection();
    
                    if (curPlayListSongs.isEmpty() == false) {
                        for (int curRow=0;curRow<curPlayListSongs.size();curRow++) {
                            Iterator sng_iter = sng.iterator();
                            while (sng_iter.hasNext()) {
                                Song cursong = (Song) sng_iter.next();
                                if (cursong.getSongid() == (long)curPlayListSongs.get(curRow)[1]) {
                                    
                                    Playlistsong curPlayListSong = new Playlistsong();
                                    curPlayListSong.setSongid(cursong);
                                    curPlayListSong.setPlaylistid(playlist);
                                    LYRA.e.persist(curPlayListSong);
                                    mPlayListSongCollection.add(curPlayListSong);
                                    
                                }
                            }
                        }
                    }
                    playlist.setPlaylistsongCollection(mPlayListSongCollection);
                    LYRA.e.persist(playlist);

                    et.commit();
                    FinisEdit();
                    parentForm.RefreshPlayListTable();
                    // Αφού αποθηκεύσαμε κλείνουμε και τη φόρμα
                    parentForm.EnableDisableForm(true);
                    this.dispose();
                } catch (Exception ex) {
                    LYRA.e.clear();
                    if (et != null) {
                        if (et.isActive()) et.rollback();
                    }
                    ex.printStackTrace(System.out);
                    LYRA.MsgBox(ex.getMessage(), "Πρόβλημα");
                }
                
            }
        }
    }
    
    private void setChanges( boolean modified )
    {
        if (modified)
        {
            tbbModify.setEnabled(true);
            tbbExit.setEnabled(true);            
        }
        //Ένδειξη ύπαρξης/μη ύπαρξης αλλαγών
        bChanges = modified;        
    }
    
    public void Insertion() {

        //Δημιουργία νέου αντικειμένου artist της κλάσης Artist
        playlist = new Playlist();
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();
        
        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, playlist, org.jdesktop.beansbinding.ELProperty.create("${name}"), txtName, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, playlist, org.jdesktop.beansbinding.ELProperty.create("${datecreated}"), dtDateCreated, org.jdesktop.beansbinding.BeanProperty.create("date"));
        bindingGroup.addBinding(binding);
        
        bindingGroup.bind();
        
        setChanges(false);
        
        StartEdit();
        txtName.requestFocus();

    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.persistence.EntityManager LYRAPUEntityManager;
    private javax.swing.JButton btnAddSelectedSongsToPlayList;
    private javax.swing.JButton btnAddSongs;
    private javax.swing.JButton btnDeleteSongs;
    private javax.swing.JButton btnExportToXML;
    private javax.swing.JButton btnImportFromXML;
    private javax.swing.JButton btnSearchAvailableSongs;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private org.jdesktop.swingx.JXDatePicker dtDateCreated;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JLabel lblAvailableSongs;
    private javax.swing.JLabel lblDateCreated;
    private javax.swing.JLabel lblName;
    private javax.swing.JLabel lblSearchAvailableSongs;
    private javax.swing.JLabel lblSongsPlayList;
    private javax.swing.JToolBar tbarManage;
    private javax.swing.JButton tbbDelete;
    private javax.swing.JButton tbbExit;
    private javax.swing.JButton tbbInsert;
    private javax.swing.JButton tbbModify;
    private javax.swing.JTable tblAvailableSongs;
    private javax.swing.JTable tblSongsPlayList;
    private javax.swing.JTextField txtName;
    private javax.swing.JTextField txtSearchAvailableSongs;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables
}

